import time

from tools.base_page import BasePage


class Pingce(BasePage):

    def start_pingce(self):
        start_pingce = ('id', 'test_tv')
        option_A = ('xpath', '//*[@text="符合"]')
        jiaojuan = ('xpath', '//*[@text="交卷"]')
        chongxin_pingce = ('id', 'com.znb.zxx:id/re_test_tv')
        if self.is_element(chongxin_pingce) != True:
            self.find(start_pingce).click()
            for num in range(20):
                self.find(option_A).click()
            self.find(jiaojuan).click()
        else:
            print('账号已评测过,进行重新评测')
            self.find_element(chongxin_pingce).click()
            for num in range(20):
                self.find(option_A).click()
                time.sleep(1)
            self.find(jiaojuan).click()

    def assert_pingce_res(self):
        '''
        验证评测结果提交成功
        :return:
        '''
        time.sleep(1)
        print(self.driver.current_activity)
        if self.driver.current_activity == 'com.work.career.planning.CareerPlanTestReportActivity':
            self.page(self.index)
            return True
        else:
            self.page(self.index)
            return False

    def cat_pingce_res(self):
        cat_pingce = ('id', 'com.znb.zxx:id/view_result_tv')
        self.find(cat_pingce).click()
        return self.assert_pingce_res()
